package com.loan.market.ui;

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.loan.market.base.BaseActivity
import com.loan.market.bean.Config
import com.loan.market.http.getHttpMap
import com.loan.market.http.request
import com.loan.market.util.SPUtil
import com.loan.market.util.config
import com.loan.market.util.http
import com.loan.market.util.initAppFlyer
import kotlinx.coroutines.async
import kotlinx.coroutines.delay

class SplashActivity : BaseActivity() {

    override fun initUi(savedInstanceState: Bundle?) {
        if (!isTaskRoot && intent != null) {
            if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN == intent.action) {
                finish()
                return
            }
        }
    }

    override fun initEvent() {

    }

    override fun initData() {
        http {
            val d1 = async { request<Config>(getHttpMap(202)) }
            async { delay(1500) }.await()
            config = d1.await()
            SPUtil.put("afKey", config?.afKey)
            initAppFlyer()
            startActivity(Intent(activity, MainActivity::class.java))
            finish()
        }
    }

    override fun getView(): View? {
        return null
    }
}